package filmsystem.example.film.controllers;

import filmsystem.example.film.dao.CinemaRepository;
import filmsystem.example.film.dao.FilmRepository;
import filmsystem.example.film.dao.ViewRepository;
import filmsystem.example.film.entities.Cinema;
import filmsystem.example.film.entities.Film;
import filmsystem.example.film.entities.View;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class HomeController {

    @Autowired
    FilmRepository filmRepository;

    @Autowired
    CinemaRepository cinemaRepository;

    @Autowired
    ViewRepository viewRepository;

    @GetMapping("/home")
    public String displayHome(Model model){

        List<Film> films = filmRepository.findAll();
        model.addAttribute("films",films);

        List<Cinema> cinemas = cinemaRepository.findAll();
        model.addAttribute("cinemas",cinemas);
        return "main/home";
    }

    @GetMapping("/")
    public String displayMaster(Model model){

        return "main/master";
    }

    @GetMapping("/memory")
    public String displayMemory(Model model){

        List<View> views = viewRepository.findAll();
        model.addAttribute("views",views);
        return "user/memory";
    }
}
